package main

import (
	"fmt"
	"math"
	"sort"
)

type Areaer interface {
	area() float32
}

type Circl struct {
	radius float32
}
type Triangle struct {
	bottom_len float32
	height     float32
}

type Rectangle struct {
	length float32
	width  float32
}

func (a *Circl) area() float32 {
	return float32(math.Pi) * a.radius * a.radius
}

func (t *Triangle) area() float32 {
	return (*t).bottom_len * (*t).height / 2
}

func (r *Rectangle) area() float32 {
	return r.length * r.width
}

type Entry struct {
	key   string
	value float32
}

func main() {
	c := &Circl{1.2}
	t := &Triangle{bottom_len: 3.0, height: 2.0}
	r := &Rectangle{length: 3.3, width: 3.2}

	areaMap := make(map[string]float32, 4)
	areaMap["c"] = c.area()
	areaMap["t"] = t.area()
	areaMap["r"] = r.area()

	entries := make([]Entry, len(areaMap))
	i := 0
	for k, v := range areaMap {
		entries[i] = Entry{k, v}
		i++
	}
	fmt.Println(entries)
	fmt.Println("~~~~~~~~~~~~~~~~~~")
	sort.Slice(entries, func(i, j int) bool {
		return entries[i].value > entries[j].value //降序
	})

	fmt.Println(entries)

}

// 阿飞老师的批改
// 实现逻辑清晰，结果正确
// 需要修改的一点小问题就是主要控制小数的位数尽量统一
